package edu.spec.xhd.widget;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import edu.spec.xhd.R;

public class ActivityWidget extends AppCompatActivity implements View.OnClickListener {

    public static final String TAG = ActivityWidget.class.getSimpleName();

    private TextView textViewHello;
    private EditText editTextName;
    private Button buttonHello;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_widget);
        initViews();
        ininListeners();
    }

    private void initViews(){
        textViewHello = findViewById(R.id.tv_hello);
        editTextName = findViewById(R.id.et_name);
        buttonHello = findViewById(R.id.btn_hello);
    }

    private void ininListeners(){
        editTextName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                Log.e(TAG, "beforeTextChanged: ");
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                Log.e(TAG, "onTextChanged: ");
            }

            @Override
            public void afterTextChanged(Editable s) {
                Log.e(TAG, "afterTextChanged: ");
            }
        });
        buttonHello.setOnClickListener(this);
    }

    public void hello(View view) {
        Log.e(TAG, "hello: ");
    }

    public void changeText(View v){
        textViewHello.setText("chage text");
    }

    @Override
    public void onClick(View v) {

    }

    class HelloOnClick implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Log.e(TAG, "HelloOnClick: ");
        }
    }

}
